package com.lagou.rabbitmq.demo.controller;

import com.lagou.rabbitmq.demo.dao.Order;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class LagouOrderController {
    @Autowired
    RabbitTemplate template;

    @RequestMapping("/index")
    public String index(){
        System.out.println(1);
        return "index";
    }
    @RequestMapping("/order/{orderId}")
    @ResponseBody
    public String toOrder(@PathVariable String orderId, Model model){
        // 发消息。 往业务交换机发消息。
        this.template.convertAndSend("exchange.biz","key.biz",orderId);
        model.addAttribute("orderId",orderId);
        // 倒计时
        return "等待支付";
    }
}
